package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: DishController
 * Description:
 *
 * @Author: Jdz
 * @Create: 2024/1/23 - 19:12
 */
@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关接口")
@Slf4j
@RequiredArgsConstructor
public class DishController {

    private final DishService dishService;

    @PostMapping
    @ApiOperation("新增菜品")
    public Result save(@RequestBody DishDTO dishDTO) {
//        log.info("新增菜品: {}", dishDTO);
        return dishService.saveWithFlavor(dishDTO);
    }

    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result<PageResult> page(DishPageQueryDTO pageQueryDTO) {
        return dishService.pageQuery(pageQueryDTO);
    }

    @DeleteMapping
    @ApiOperation("菜品批量删除")
    public Result delete(@RequestParam("ids") List<Long> ids) {
        return dishService.deleteBatch(ids);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品")
    public Result<DishVO> getById(@PathVariable Long id) {
        return dishService.getByIdWithFlavor(id);
    }

    @PutMapping
    @ApiOperation("修改菜品")
    public Result update(@RequestBody DishDTO dishDTO) {
        return dishService.updateWithFlavor(dishDTO);
    }

    @GetMapping("/list")
    @ApiOperation("根据id和菜品名称查询菜品")
    public Result<List<DishVO>> list(@RequestParam(required = false) Long categoryId, @RequestParam(required = false) String name) {
        return dishService.list(categoryId, name);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("启用禁用")
    public Result startOrStop(@PathVariable("status") Integer status, @RequestParam Long id) {
        return dishService.startOrStop(status, id);
    }
}
